﻿// *---------------------------------------------------------------------------------------------------------*
// Solution:         JwikIDE									
// Project:           JwiKIDE								
// Source File:    BigEndianBinaryReader.cs									
// *---------------------------------------------------------------------------------------------------------*
// 
// © 2012 Digital Six Labs, LLC All Rights Reserved
// 
// Permission is hereby granted, free of charge, to any person obtaining a copy of this software 
// and associated documentation files (the "Software"), to deal in the Software without restriction, 
// including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, 
// and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, 
// subject to the following conditions:
// 
// The above copyright notice and this permission notice shall be included in all copies or substantial 
// portions of the Software.
// 
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT 
// LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN 
// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 
// SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
// 
// 
// 
// 
namespace JwiKIDE.Utilities
{
    using System;
    using System.Collections.Generic;
    using System.IO;
    using System.Linq;
    using System.Text;

    /// <summary>
    /// TODO: Update summary.
    /// </summary>
    public class BigEndianBinaryReader : BinaryReader
    {

        public BigEndianBinaryReader(Stream s) :base(s)
        {
            
        }

        public override short ReadInt16()
        {
            Int16 retval;
            byte b1, b2;

            b1 = base.ReadByte();
            b2 = base.ReadByte();
            retval = b2;
            retval +=(Int16)( b1 << 8);
            return retval;

        }
        public override int ReadInt32()
        {
            Int32 retval;
            byte b1, b2, b3, b4;
            b1 = base.ReadByte();
            b2 = base.ReadByte(); 
            b3 = base.ReadByte();
            b4 = base.ReadByte();
            retval = b4;
            retval += (Int32)(b3 << 8);
            retval += (Int32)(b2 << 16);
            retval += (Int32)(b1 << 24);
            return retval;
        }
        public override Int64 ReadInt64()
        {
            Int32 retval;
            byte b1, b2, b3, b4,b5,b6,b7,b8;
            b1 = base.ReadByte();
            b2 = base.ReadByte();
            b3 = base.ReadByte();
            b4 = base.ReadByte();
            b5 = base.ReadByte();
            b6 = base.ReadByte();
            b7 = base.ReadByte();
            b8 = base.ReadByte();
            retval = b8;
            retval += (Int32)(b7 << 8);
            retval += (Int32)(b6 << 16);
            retval += (Int32)(b5 << 24);
            retval += (Int32)(b4 << 32);
            retval += (Int32)(b3 << 40);
            retval += (Int32)(b2 << 48);
            retval += (Int32)(b1 << 56);
            return retval;
        }

    }
}
